#include "RegeditHelper.h"

bool Regedit::read(HKEY root, LPCWSTR lpSubKey, std::wstring &value)
{
    HKEY hKey;
    LONG lResult = RegOpenKeyEx(root, lpSubKey, 0, KEY_READ, &hKey);
    if (lResult != ERROR_SUCCESS) {
        std::cerr << "Failed to open registry key!" << std::endl;
        return false;
    }
    WCHAR szProductKey[256];
    DWORD dwBufferSize = sizeof(szProductKey);
    lResult = RegQueryValueEx(hKey, L"InstallLocation", NULL, NULL,
                              reinterpret_cast<LPBYTE>(szProductKey),
                              &dwBufferSize);

    if (lResult != ERROR_SUCCESS) {
        std::cerr << "Failed to query registry value!" << std::endl;
        return false;
    }
    value = szProductKey;
    RegCloseKey(hKey);
    return true;
}
